﻿Public Class frmproductgrouplist
    Dim Strsql As String
    Dim Mysql As New ClsSQLhelper
#Region "Function"
    Sub Load_Data(Optional ByVal Section_name As String = "")
        Try
            Dim DS As New DataSet
            Strsql = "select section_id,section_name,note,active from section where section_id <> 0 "
            If Section_name <> "" Then
                Strsql = Strsql & "  and section_name like  '" & Me.TxtSearch.Text & "%'"
            End If
            Strsql = Strsql & " order by active desc ,section_name"
            Me.EventLog1.WriteEntry(Me.Name & " : " & Strsql, EventLogEntryType.Information, 1)
            DS = Mysql.GetMYSQLDataset(Strsql, "DS_section", "section")
            Pn_Framework.Set_GridSetting(Me.gridsection, DS)
            With gridsection
                .Columns(0).HeaderText = "ลำดับ"
                .Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .Columns(1).HeaderText = "ชื่อกลุ่มรายการ"
                .Columns(2).HeaderText = "หมายเหตุ"
                .Columns(3).HeaderText = "เปิดใช้งาน"
            End With
        Catch ex As Exception
            Me.EventLog1.WriteEntry(Me.Name & " : " & ex.Message, EventLogEntryType.Error, 1)
            MsgBox(ex.Message)
        End Try

    End Sub
#End Region
    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Me.Dispose()
    End Sub

    Private Sub BtnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNew.Click
        frmproductgroup.New_Entry_State = True
        frmproductgroup.Show()
    End Sub

    Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
        frmproductgroup.New_Entry_State = False
        frmproductgroup.Txtid.Text = gridsection.Rows(gridsection.CurrentCell.RowIndex).Cells(0).Value
        frmproductgroup.TxtName.Text = gridsection.Rows(gridsection.CurrentCell.RowIndex).Cells(1).Value
        frmproductgroup.TxtNote.Text = gridsection.Rows(gridsection.CurrentCell.RowIndex).Cells(2).Value
        frmproductgroup.ChkActive.Checked = gridsection.Rows(gridsection.CurrentCell.RowIndex).Cells(3).Value
        frmproductgroup.Show()
    End Sub

    Private Sub frmproductgrouplist_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Load_Data()
    End Sub

    Private Sub TxtSearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtSearch.KeyDown
        If e.KeyCode = Keys.Enter Then
            If Me.TxtSearch.Text = "" Then
                Load_Data()
            Else
                Load_Data(Me.TxtSearch.Text)
            End If

        End If
    End Sub


    Private Sub gridsection_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gridsection.CellDoubleClick
        frmproductgroup.New_Entry_State = False
        frmproductgroup.Txtid.Text = gridsection.Rows(gridsection.CurrentCell.RowIndex).Cells(0).Value
        frmproductgroup.TxtName.Text = gridsection.Rows(gridsection.CurrentCell.RowIndex).Cells(1).Value
        frmproductgroup.TxtNote.Text = gridsection.Rows(gridsection.CurrentCell.RowIndex).Cells(2).Value
        frmproductgroup.ChkActive.Checked = gridsection.Rows(gridsection.CurrentCell.RowIndex).Cells(3).Value
        frmproductgroup.Show()
    End Sub

    Private Sub TxtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtSearch.TextChanged

    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub

    Private Sub gridsection_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gridsection.CellContentClick

    End Sub
End Class